{
  "cells": [
    {
      "attachments": {},
      "cell_type": "markdown",
      "metadata": {
        "id": "TkR0saXIcvyC"
      },
      "source": [
        "# MVSep MDX23 Colab\n",
        "Colab version of MDX23 algorithm from [MVSEP.COM](https://www.mvsep.com) with some tweaks:\n",
        "\n",
        "<font color=red>v2.4 is now available ! => https://github.com/jarredou/MVSEP-MDX23-Colab_v2/</font>\n",
        "* updated with new Kim Vocal 2 & UVR-MDX-Instr-HQ3 models\n",
        "* folder batch processing\n",
        "* fixed high frequency bleed in vocals\n",
        "* fixed volume compensation for MDX models\n",
        "\n",
        "Credits:\n",
        "* [https://github.com/ZFTurbo/MVSEP-MDX23-music-separation-model](https://github.com/ZFTurbo/MVSEP-MDX23-music-separation-model)\n",
        "* Models by [Demucs](https://github.com/facebookresearch/demucs), [Anjok](https://github.com/Anjok07/ultimatevocalremovergui) & [Kimberley Jensen](https://github.com/KimberleyJensen)\n",
        "* Adaptation & tweaks by [jarredou](https://github.com/jarredou/MVSEP-MDX23-Colab_v2/)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "uWX5WOqjU0QC"
      },
      "outputs": [],
      "source": [
        "#@markdown #Installation\n",
        "#@markdown *Run this cell to install MVSep-MDX23*\n",
        "print('Installing... This will take 1 minute...')\n",
        "%cd /content\n",
        "from google.colab import drive\n",
        "drive.mount('/content/drive')\n",
        "!git clone -b 2.0 https://github.com/jarredou/MVSEP-MDX23-Colab_v2 &> /dev/null\n",
        "%cd /content/MVSEP-MDX23-Colab_v2\n",
        "!pip install -r requirements.txt &> /dev/null\n",
        "# onnxruntime-gpu nightly fix for cuda12.2\n",
        "!python -m pip install ort-nightly-gpu --index-url=https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ort-cuda-12-nightly/pypi/simple/\n",
        "print('Installation done !')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "V7n1nXKsU4sd"
      },
      "outputs": [],
      "source": [
        "#@markdown #Separation\n",
        "from pathlib import Path\n",
        "import glob\n",
        "\n",
        "%cd /content/MVSEP-MDX23-Colab_v2\n",
        "def console(t):\n",
        "    get_ipython().system(t)\n",
        "\n",
        "#file_path = '/content/drive/MyDrive/mvsep_dataset/' #@param {type:\"string\"}\n",
        "folder_path = '/content/drive/MyDrive/' #@param {type:\"string\"}\n",
        "output_folder = '/content/drive/MyDrive/output' #@param {type:\"string\"}\n",
        "overlap_large = 0.6 #@param {type:\"slider\", min:0.1, max:1, step:0.05}\n",
        "overlap_small = 0.5 #@param {type:\"slider\", min:0.1, max:1, step:0.05}\n",
        "\n",
        "#@markdown *Use lower chunk_size if you have memory errors*\n",
        "chunk_size = 500000 #@param {type:\"slider\", min:100000, max:1000000, step:100000}\n",
        "\n",
        "#console(f'python inference.py --large_gpu --chunk_size {chunk_size} --input_audio \"{file_path}\" --output_folder \"./results/{filename}\"')\n",
        "for file_path in glob.glob(folder_path+\"/*\"):\n",
        "  filename =  Path(file_path).stem\n",
        "  Path(output_folder,filename).mkdir(parents=True, exist_ok=True)\n",
        "  console(f'python inference.py --large_gpu --chunk_size {chunk_size} --input_audio \"{file_path}\" --overlap_large {overlap_large} --overlap_small {overlap_small} --output_folder \"{output_folder}\"/\"{filename}\"')\n",
        "  "
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "gpuClass": "standard",
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
